﻿using System;
using System.Collections.Generic;
using System.Text;

namespace 设计模式
{
    public class bosscome
    {
        public static void main() {
            secretary s1 = new secretary();
            stockobserver t1 = new stockobserver("z1", s1);
            nbaobserver t2=new nbaobserver("z2",s1);

            s1.attach(t1);
            s1.attach(t2);

            s1.secretary_action="老板来了！";
            s1.notify();
        }

    }


    public abstract class Observer
    {

        public string name;
        public secretary sub;

        public Observer(string name, secretary sub)
        {
            this.name = name;
            this.sub = sub;
        }

        public abstract void update();


    }

    class stockobserver : Observer
    {
        public stockobserver(string name, secretary sub) : base(name, sub) { }

        public override void update()
        {
            Console.WriteLine("{0} {1} 关闭股票行情，继续工作！", sub.secretary_action, name);
        }
    }

    class nbaobserver : Observer
    {
        public nbaobserver(string name, secretary sub) : base(name, sub) { }

        public override void update()
        {
            Console.WriteLine("{0} {1} 关闭nba直播，继续工作！", sub.secretary_action, name);
        }
    }


    public class secretary
    {

        public string secretary_action;

        private List<Observer> observers = new List<Observer>();
        //private string action;

        public void attach(Observer observer) {
            observers.Add(observer);
        }

        public void detach(Observer observer) {
            observers.Remove(observer);
        }

        public void notify() {
            foreach (Observer o in observers)
                o.update();
        }



    }
}
